<template>
    <div>
        <!-- 面包屑导航 -->
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>订单管理</el-breadcrumb-item>
            <el-breadcrumb-item>订单列表</el-breadcrumb-item>
        </el-breadcrumb>
        <!-- 卡片视图区域 -->
        <el-card>
            <el-row>
                <el-col :span="7">
                    <el-input v-model="queryInfo.query"  @keyup.enter.native="getOrderList" placeholder="请输入内容" clearable>
                        <el-button slot="append" icon="el-icon-search" @click="getOrderList"></el-button>
                    </el-input>
                </el-col>
            </el-row>
             <el-alert
                :closable="false"
                title="注: 所有物流进度均为固定数据"
                type="warning"
                show-icon>
            </el-alert>
            <!-- 订单列表数据 -->
            <el-table :data="orderList" border stripe>
                <el-table-column type="index" label="#"></el-table-column>
                <el-table-column prop="order_number" label="订单编号"></el-table-column>
                <el-table-column prop="order_price" label="订单价格"></el-table-column>
                <el-table-column label="是否付款(支付方式)">
                    <template slot-scope="scope">
                        <el-tag 
                        :type="scope.row.order_pay === '1'?'primary' : 
                        scope.row.order_pay === '2'?'success':'warning'" 
                        v-if="scope.row.pay_status !== '0'">
                            {{scope.row.order_pay === '1'?'支付宝' : scope.row.order_pay === '2'?'微信':'银行卡'}}
                        </el-tag>
                        <el-tag type="danger" v-else>未付款</el-tag>
                    </template>
                </el-table-column>  
                <el-table-column prop="is_send" label="是否发货"></el-table-column>                
                <el-table-column label="下单时间">
                    <template slot-scope="scope">
                        {{scope.row.create_time | dateFormat}}
                    </template>
                </el-table-column>
                <el-table-column  label="操作">
                    <template slot-scope="scope">
                        <el-tooltip content="修改地址" placement="top">
                            <el-button type="primary"  icon="el-icon-edit" size="mini"
                            @click="showbox(scope.row.order_id)"></el-button>
                        </el-tooltip>
                        <el-tooltip content="物流进度" placement="top">
                            <el-button type="success" icon="el-icon-location" size="mini"
                            @click="showProhressBox(scope.row.order_id)"></el-button>  
                        </el-tooltip> 
                        <el-tooltip effect="dark"
                            content="修改订单" placement="right" :enterable="false">
                            <el-button type="warning"
                            icon="el-icon-edit" size="mini"
                            @click="goEditPage(scope.row.order_id)" circle></el-button>
                        </el-tooltip>          
                    </template>
                </el-table-column>                                                         
            </el-table>
            <Page :total="total" :params="queryInfo" @handleCurrentChange="handleCurrentChange"
            @handleSizeChange="handleSizeChange"></Page>
        </el-card>
        <!-- 修改地址 -->
        <UpdateRess ref="updateRef"></UpdateRess>
        <!-- 物流进度 -->
        <ProhressBox ref="ProhressBoxRef" :progressInfo="progressInfo"></ProhressBox>
    </div>
</template>
<script>
import Page from '@/components/Page.vue'
import UpdateRess from './UpdateRess.vue'
import ProhressBox from './ProhressBox.vue'
export default {
    name:"Or-der",
    components:{Page,UpdateRess,ProhressBox},
    data(){
        return{
            queryInfo:{
                query: "",
                pagesize:10,
                pagenum: 1,
            },
            total:0,
            orderList:[],
            // 物流信息
            progressInfo:[
                {
                    "time": "2018-05-10 09:39:00",
                    "ftime": "2018-05-10 09:39:00",
                    "context": "已签收,感谢使用顺丰,期待再次为您服务",
                    "location": ""
                    },
                    {
                    "time": "2018-05-10 08:23:00",
                    "ftime": "2018-05-10 08:23:00",
                    "context": "[北京市]北京海淀育新小区营业点派件员 顺丰速运 95338正在为您派件",
                    "location": ""
                    },
                    {
                    "time": "2018-05-10 07:32:00",
                    "ftime": "2018-05-10 07:32:00",
                    "context": "快件到达 [北京海淀育新小区营业点]",
                    "location": ""
                    },
                    {
                    "time": "2018-05-10 02:03:00",
                    "ftime": "2018-05-10 02:03:00",
                    "context": "快件在[北京顺义集散中心]已装车,准备发往 [北京海淀育新小区营业点]",
                    "location": ""
                    },
                    {
                    "time": "2018-05-09 23:05:00",
                    "ftime": "2018-05-09 23:05:00",
                    "context": "快件到达 [北京顺义集散中心]",
                    "location": ""
                    },
                    {
                    "time": "2018-05-09 21:21:00",
                    "ftime": "2018-05-09 21:21:00",
                    "context": "快件在[北京宝胜营业点]已装车,准备发往 [北京顺义集散中心]",
                    "location": ""
                    },
                    {
                    "time": "2018-05-09 13:07:00",
                    "ftime": "2018-05-09 13:07:00",
                    "context": "顺丰速运 已收取快件",
                    "location": ""
                    },
                    {
                    "time": "2018-05-09 12:25:03",
                    "ftime": "2018-05-09 12:25:03",
                    "context": "卖家发货",
                    "location": ""
                    },
                    {
                    "time": "2018-05-09 12:22:24",
                    "ftime": "2018-05-09 12:22:24",
                    "context": "您的订单将由HLA（北京海淀区清河中街店）门店安排发货。",
                    "location": ""
                    },
                    {
                    "time": "2018-05-08 21:36:04",
                    "ftime": "2018-05-08 21:36:04",
                    "context": "商品已经下单",
                    "location": ""
                    }
            ]   
        }
    },
    watch:{
        "queryInfo.query"(value){
            if(value === ""){
                this.getOrderList();
            }
        }
    },
    created(){
        this.getOrderList();
    },
    methods:{
        handleCurrentChange(value){
            this.queryInfo.pagenum = value;
            this.getOrderList()
        },
        handleSizeChange(value){
            this.queryInfo.pagesize = value;
            this.getOrderList()            
        },
        /**
         * @description 获取订单数据
         */
        async getOrderList(){
           const {data:res} = await this.$http.get('orders',{params:this.queryInfo});
            if(res.meta.status !== 200){
                return this.$message.error("获取订单列表失败");
            }
            this.orderList = res.data.goods;
            this.total = res.data.total;
            
        },
        /**
         * @description 修改地址
         */
        showbox(){
            this.$refs.updateRef.AddRessDialogVisible = true;
        },
        // 物流
        showProhressBox(){
            // const {data:res} = await this.$http.get(`/kuaidi/1106975712662`)
            // if(res.meta.status !== 200){
            //     return this.$message.error("获取信息失败");
            // }
            // this.progressInfo = res.data;
            this.$refs.ProhressBoxRef.ProgRessDialogVisible = true;
        },
        /**
         * @name goEditPage
         * @description 修改订单
         */
        goEditPage(id){
            // 前往编辑订单页面
            this.$router.push('/orders/edit/' + id)
        }
    },
}
</script>
<style lang="less" scoped>
.el-table{
     margin-bottom: 10px;
}
</style>


